<?php
include_once("functions/db_manipulate.php");

if (!init()) {
    redirect("login.php");
}

$fliesResultSet = getLastFlies();

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title>Мушки</title>
    <link rel="stylesheet" type="text/css" href="css/navigation.css">
    <link rel="stylesheet" type="text/css" href="css/square.css">
    <link rel="stylesheet" type="text/css" href="css/menu.css">
    <link rel="stylesheet" type="text/css" href="css/common.css">
    <link rel="stylesheet" type="text/css" href="css/flies.css">
    <script src="resources/jquery.js"></script>
    <script language="JavaScript">
        function customFormSubmit() {
            $('#maximized_navigation').show();
            $('#commentform').submit();
        }
    </script>
    <meta charset="UTF-8">
</head>
<body class="body">

<?php
include_once("menu.php");
?>
<div id="square">
    <div class="fliesdiv">

        <div class="fliesheader">
            Наши мушки:
        </div>

        <?php
        while ($fly = mysql_fetch_assoc($fliesResultSet)) {

            $comments = countFlyComments($fly['id']);
            ?>
            <div class="flydiv">
                <img src="fly_img/<?= $fly['path'] ?>" class="flyimg">

                <div class="flyheader">
                    <?= htmlspecialchars($fly['header']) ?>
                </div>

                <div class="flylegend">
                    <?= htmlspecialchars($fly['legend']) ?>
                </div>

                <div id="flyinfo">
                    <div id="author">
                        <?= $fly['author'] ?>
                    </div>
                    <div id="date">
                        <?= $fly['date'] ?>
                    </div>
                    <div id="date">
                        <?= $fly['time'] ?>
                    </div>
                </div>

                <div class="flybuttonsdiv">

                    <div class="flybutton"
                        <?php if (!isLiked("f", $fly['id'])) {
                            ?>
                            onclick="location.href = 'fly_like_handler.php?fid=<?= $fly['id'] ?>&like=1'"
                        <?php
                        }
                        ?>
                        >
                        +(<?= $fly['likes'] ?>)
                    </div>

                    <div class="flybutton"
                        <?php if (!isDisiked("f", $fly['id'])) {
                            ?>
                            onclick="location.href = 'fly_like_handler.php?fid=<?= $fly['id'] ?>&dislike=1'"
                        <?php
                        }
                        ?>
                        >
                        -(<?= $fly['dislikes'] ?>)
                    </div>

                    <div class="flybutton" onclick="location.href = 'fly.php?fid=<?= $fly['id'] ?>'">
                        Комментарии(<?= $comments ?>)
                    </div>


                </div>
            </div>
        <?php
        }
        ?>

        <div class="archivebutton" onclick="location.href='flies_archive.php'">
            Архив мушек
        </div>

        <div class="flyformdiv">
            <form enctype="multipart/form-data" accept-charset="UTF-8" action="fly_handler.php"
                  method="post"
                  id="commentform">
                <span style="font-weight: bold">Новая мушка:</span>
                <textarea name="header" id="textarea" rows="1" placeholder="Название мушки.."
                          required="true"></textarea>
                <textarea name="legend" id="textarea" rows="11" placeholder="Описание мушки.."></textarea>

                <input type="hidden" name="MAX_FILE_SIZE" value="25000000"/>

                <div style="display: inline-block; width: 100%">
                    <div id="fileinputdiv">
                        <input name="image" required type="file" accept=".jpg, .png, .jpeg, .gif" id="realfileinput">

                        <div id="fileinput">Главное</div>
                    </div>
                    <br>

                    <div id="fileinputdiv">
                        <input name="images[]" type="file" accept=".jpg, .png, .jpeg, .gif" id="realfileinput" multiple>

                        <div id="fileinput">Изображение</div>
                    </div>

                    <div id="flybutton" onclick="customFormSubmit()">Продолжить</div>

                </div>
            </form>
        </div>

    </div>
</div>


<?php
include_once("navigation.html");
?>

</body>
</html>